package com.gzhu.knowledgeAdmin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzhu.knowledgeAdmin.dao.TDxmbTMapper;
import com.gzhu.knowledgeAdmin.entity.TDxmbT;
import com.gzhu.knowledgeAdmin.service.TDxmbTService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

@Service
public class TDxmbTServiceImpl extends ServiceImpl<TDxmbTMapper, TDxmbT> implements TDxmbTService {
    @Resource
    private TDxmbTMapper tDxmbTMapper;

    @Resource
    private com.gzhu.knowledgeAdmin.dao.TDxjgTMapper TDxjgTMapper;

    @Override
    public List<TDxmbT> selectStatus() {
        return tDxmbTMapper.selectStatus();
    }

    @Override
    public List<TDxmbT> getAllUsers() {
        return tDxmbTMapper.selectList(null);
    }

    @Override
    public TDxmbT getUserById(Long id) {
        return tDxmbTMapper.selectById(id);
    }

    @Override
    public void updateUser(TDxmbT tDxmbT) {
        tDxmbTMapper.updateById(tDxmbT);
    }

    @Override
    public void deleteUserById(Long fId) {
        tDxmbTMapper.deleteById(fId);
    }

    @Transactional
    @Override
    public void insertUser(TDxmbT tDxmbT) {
        // 设置f_cjsj为当前时间
        tDxmbT.setFCjsj(new Date());

        // 插入数据，此时MyBatis应当自动填充生成的f_id回对象tDxmbT中
        tDxmbTMapper.insert(tDxmbT);

        // 将生成的f_id设置为f_gsid
        tDxmbT.setFGsid(tDxmbT.getFId());

        // 更新对象以反映f_gsid的变化
        tDxmbTMapper.updateById(tDxmbT);
    }


    @Override
    public List<TDxmbT> selectByAll(String fmbmc, String fqm, String fnr, String fzt, String fmblx, String fdxlx) {
        return tDxmbTMapper.selectAll(fmbmc,fqm,fnr,fzt,fmblx,fdxlx);
    }

    }
